package com.gitee.dufafei.spark.pattern

import org.slf4j.{Logger, LoggerFactory}

trait Logging {

  private lazy val log: Logger = LoggerFactory.getLogger(name)

  protected def name: String = this.getClass.getName.stripSuffix("$")

  protected def debug(msg: => String): Unit = if(log.isDebugEnabled) log.debug(msg)

  protected def info(msg: => String): Unit = if(log.isInfoEnabled) log.info(msg)

  protected def warn(msg: => String): Unit = if(log.isWarnEnabled) log.warn(msg)

  protected def error(msg: => String): Unit = if(log.isErrorEnabled) log.error(msg)

  protected def error(msg: => String, throwable: Throwable): Unit =  if (log.isErrorEnabled) log.error(msg, throwable)
}
